package com.jd.finance.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jd.finance.core.mapper.RoleMapper;
import com.jd.finance.core.pojo.entity.Role;
import com.jd.finance.core.service.RoleService;
import com.jd.finance.result.BaseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-20
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Resource
    private AdminUtilsServiceImpl adminUtilsServiceimpl;

    @Resource
    private RoleMapper roleMapper;

    /**
     * 修改关于我们
     * @param uid
     * @return
     */
    @Override
    public BaseResult selectAllRoleInfo(Integer uid) {
        if(uid == null){
            log.error("uid为空");
            return BaseResult.error().message("uid为空");
        }
        if (!adminUtilsServiceimpl.isHR(uid)){
            log.error("当前登录用户不是HR账户");
            return BaseResult.error().message("当前登录用户不是HR账户");
        }

        List<Role> roles = roleMapper.selectList(null);
        return BaseResult.ok().data("roles:",roles);
    }

    /**
     * 添加角色信息
     * @param uid hr的id
     * @param roleName 角色名称
     * @param roleExplain 角色说明
     * @param roleOrgan 所属部门
     * @param request
     * @return
     */
    @Override
    public BaseResult addRoleInfo(Integer uid, String roleName, String roleExplain, String roleOrgan, HttpServletRequest request) {
        if(uid == null){
            log.error("uid为空");
            return BaseResult.error().message("uid为空");
        }
        Role role = new Role();
        role.setRoleName(roleName);
        role.setRoleExplain(roleExplain);
        role.setRoleOrgan(roleOrgan);
        int i = roleMapper.insert(role);
        if (i == 0){
            log.error("添加失败");
            return BaseResult.error().message("添加失败");
        }
        return BaseResult.ok().data("tianjiajieguo:",i);
    }


}
